1138B - Circus - CodeForces Solution


brute force greedy math strings *1800

Please click on ads to support us..

C++ Code:

/*
Problem: 1138B
Date: 22-01-2024 05:16 AM
*/


#include <iostream>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

int n;
string c, a;
vector<int> s[2][2];
vector<int> f;

int main() {
	cin >> n >> c >> a;
	for(int i = 0; i < n; i++) {
		s[c[i] - '0'][a[i] - '0'].push_back(i + 1);
	}
	int na = s[0][0].size(), nb = s[0][1].size(), nc = s[1][0].size(), nd = s[1][1].size();
	for(int a = 0; a <= na; a++) {
		for(int b = 0; b <= nb; b++) {
			int d = a - n/2 + nb + nd;
			int c = nb + nd - b - 2 * d;
			if(0 <= c && c <= nc && 0 <= d && d <= nd) {
				for(int i = 0; i < a; i++) {
					cout << s[0][0][i] << " ";
				}for(int i = 0; i < b; i++) {
					cout << s[0][1][i] << " ";
				}for(int i = 0; i < c; i++) {
					cout << s[1][0][i] << " ";
				}for(int i = 0; i < d; i++) {
					cout << s[1][1][i] << " ";
				}
				return 0;
			}
		}
	}
	cout << -1 << endl;
}


Comments

Submit
0 Comments
More Questions

1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB